<!-- 员工签订合同 与 入职界面 -->
<template>
  <div class="rthcHead">
    <div class="rthcImg">
      <img src="@/assets/img/personnelImage/岗位需求库.png">
      <span class="rthcTi" title="入职通知 与 入职">入职通知 与 入职</span>
    </div>
    <div class="rthc-handle">
      <span class="rthc-handle-pri" style="margin-right: 100px">
        <el-button type="primary" @click="ByIh">新增员工入职</el-button>
      </span>
    </div>
  </div>
  <div class="interview">
    <el-table :data="tabData" size="small" ref="tableRef">
      <el-table-column prop="rcId" type="selection" :selectable="selectableStatus" width="55"/>
      <el-table-column prop="candidate" label="候选人"/>
      <el-table-column prop="contactPhone" label="联系电话"/>
      <el-table-column prop="firstInterview" label="初试结果">
        <template #default="s">
          <interview-handle-result-item :interview-result="s.row.firstInterview"/>
        </template>
      </el-table-column>
      <el-table-column prop="secondInterview" label="复试结果">
        <template #default="s">
          <interview-handle-result-item :interview-result="s.row.secondInterview"/>
        </template>
      </el-table-column>
      <el-table-column prop="threeInterview" label="终试结果">
        <template #default="s">
          <interview-handle-result-item :interview-result="s.row.threeInterview"/>
        </template>
      </el-table-column>
      <el-table-column prop="candidatePosition" label="定岗岗位"/>
      <el-table-column prop="" label="是否录用">
        <template #default="s">
          <span v-if="s.row.isHire === 1">已录用</span>
          <span v-else-if="s.row.isHire === 2">待入职</span>
          <span v-else>未录用</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template #default="s">
          <el-button type="warning" size="small" @click="remOffice(s.row)">移除</el-button>
          <el-button v-if="s.row.firstInterview === 2 || s.row.secondInterview === 2 || s.row.threeInterview === 2"
                     type="primary" size="small"
                     disabled>发送office
          </el-button>
          <el-button v-else @click="EditOffice(s.row)" type="primary" size="small">发送offer</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next" :page-size="paging.pageSize" :total="paging.total"
                   @current-change="switchPageNum"/>
  </div>
  <el-dialog v-model="dialogTableVisible" title="填写offer" width="700px">
    <el-form :model="takeOn" ref="tForm" :rules="rtules" label-position="left" label-width="80px" size="default"
             @submit.prevent>
      <div class="table-container">
        <table class="table-layout">
          <tbody>
          <tr>
            <td>
              <div class="static-content-item">
                <div>姓名：</div>
              </div>
            </td>
            <td>
              <el-form-item label="" label-width="0" prop="hired" class="required">
                <el-input v-model="takeOn.hired" readonly="true" type="text" clearable></el-input>
              </el-form-item>
            </td>
            <td>
            </td>
          </tr>
          <tr>
            <td>
              <div class="static-content-item">
                <div>定岗岗位:</div>
              </div>
            </td>
            <td>
              <el-form-item label="" label-width="0" prop="applyToPosition" class="required">
                <el-input v-model="takeOn.applyToPosition" readonly="true" type="text" clearable></el-input>
              </el-form-item>
            </td>
            <td>
            </td>
          </tr>
          <tr>
            <td>
              <div class="static-content-item">
                <div>邮箱：</div>
              </div>
            </td>
            <td>
              <el-form-item label="" label-width="0" prop="mailIds" class="required">
                <el-input v-model="takeOn.mailIds" readonly="true" type="text" clearable></el-input>
              </el-form-item>
            </td>
            <td>
            </td>
          </tr>
          <tr>
            <td>
              <div class="static-content-item">
                <div>报到日期：</div>
              </div>
            </td>
            <td>
              <el-form-item label="" label-width="0" prop="checkinDate" class="required">
                <el-date-picker v-model="takeOn.checkinDate" type="date" class="full-width-input"
                                :disabled-date="publishDateAfter"
                                format="YYYY-MM-DD" value-format="YYYY-MM-DD" clearable></el-date-picker>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>
              <div class="static-content-item">
                <div>合同期限：</div>
              </div>
            </td>
            <td>
              <el-form-item label="" label-width="0" prop="addDateVal" class="required">
               <el-select v-model="addDateVal" class="m-2" placeholder="合同年限">
                <el-option
                    v-for="item in options"
                    @click="DateAdd(item.value)"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                />
              </el-select>
              </el-form-item>
            </td>
            <td>
            </td>
          </tr>
          <tr>
            <td>
              <div class="static-content-item">
                <div>合同有效期：</div>
              </div>
            </td>
            <td>
              <el-form-item label="" label-width="0" prop="contractDate" class="required">
                <el-date-picker is-range v-model="takeOn.contractDate" type="daterange"
                                :disabled-date="publishDateAfter"
                                readonly
                                class="full-width-input" format="YYYY-MM-DD" value-format="YYYY-MM-DD" clearable>
                </el-date-picker>
              </el-form-item>
            </td>
            <td>
            </td>
          </tr>
          <tr>
            <td>
              <div class="static-content-item">
                <div>试用期：</div>
              </div>
            </td>
            <td>
              <el-form-item label="" label-width="0" prop="trialDate" class="required">
                <el-date-picker is-range v-model="takeOn.trialDate" type="daterange"
                                :disabled-date="publishDateAfter"
                                class="full-width-input" format="YYYY-MM-DD" value-format="YYYY-MM-DD" clearable>
                </el-date-picker>
              </el-form-item>
            </td>
            <td>
            </td>
          </tr>
          <tr>
            <td>
              <div class="static-content-item">
                <div>薪资：</div>
              </div>
            </td>
            <td>
              <el-form-item label="" label-width="0" prop="salary" class="required">
                <el-input v-model="takeOn.salary" type="text" clearable
                          maxlength="6"
                          minlength="4"
                          oninput="value=value.replace(/[^\d]/g,'')"/>
              </el-form-item>
            </td>
            <td>
            </td>
          </tr>
          </tbody>
        </table>
      </div>
      <el-row>
        <el-col :span="2" :offset="18" class="grid-cell">
          <div class="static-content-item">
            <el-button @click="SendOffice">保存</el-button>
          </div>
        </el-col>
        <el-col :span="3" offset="1" class="grid-cell">
          <div class="static-content-item">
            <el-button>取消</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
import {
  DelinterviewRecordAndResume,
  getInterviewHandlePageInfo, insertListByEntery,
  sendEmailByIHandleSendOffice
} from "../../../network/per/interview_handle";
import InterviewHandleResultItem from "./comps/InterviewHandleResultItem.vue";
import DateFormatUtil from "../../../assets/js/personnelJs/DateFormatUtil";

export default {
  name: "InterviewHandle",
  components: {InterviewHandleResultItem},
  data() {
    return {
      addDateVal: "",
      options: [
        {
          value: 6,
          label: '半年'
        }, {
          value: 12,
          label: '一年'
        }, {
          value: 24,
          label: '两年'
        }, {
          value: 36,
          label: '三年'
        }, {
          value: 60,
          label: '五年'
        },
      ],
      multipleSelection: [],
      tabData: [],
      paging: {
        pageNum: 1,
        pageSize: 10,
        total: 10
      },
      selection: null,
      dialogTableVisible: false,
      takeOn: {
        rid: null,
        rcId: null,
        jobNumber: null,
        hired: "",
        applyToPosition: "",
        mailIds: "",
        checkinDate: null,
        contractDate: [],
        trialDate: null,
        salary: "",
      },
      entryList: [],
      rtules: {
        hired: [
          {
            required: true,
            message: '字段值不可为空',
          }],
        applyToPosition: [{
          required: true,
          message: '字段值不可为空',
        }],
        mailIds: [{
          required: true,
          message: '字段值不可为空',
        }],
        checkinDate: [{
          required: true,
          message: '字段值不可为空',
        }],
        contractDate: [{
          required: true,
          message: '字段值不可为空',
        }],
        trialDate: [{
          required: true,
          message: '字段值不可为空',
        }],
        salary: [{
          required: true,
          message: '字段值不可为空',
        }
        ],
      },
    }
  },
  methods: {
    // 当前日期 追加
    DateAdd(number) {
      this.takeOn.contractDate = []
      let date = new Date();
      date.setDate(date.getDate() + 2);
      this.takeOn.contractDate.push(DateFormatUtil.DateUtil.formatDate(date))
      date.setMonth(date.getMonth() + number);
      this.takeOn.contractDate.push(DateFormatUtil.DateUtil.formatDate(date))
    },
    // 时间限制
    publishDateAfter(time) {
      return time.getTime() < Date.now();
    },
    // 员工入职数组赋值
    ByIh() {
      let a = this.$refs.tableRef.getSelectionRows();
      for (let i = 0; i < a.length; i++) {
        let s = {
          empId: a[i].rid,
          interviewArrid: a[i].iaId,
          jobDemandId: a[i].jdid,
          resumeClassId: a[i].rcId
        }
        this.entryList.push(s);
      }
      if (this.entryList.length <= 0) {
        this.$notify({
          title: '未选择错误',
          message: '请选择入职员工!',
          type: 'error'
        })
      } else {
        // this.$router.push({path: '/ei',})
        this.insertEntery();
      }
    },
    // 员工入职
    insertEntery() {
      insertListByEntery(this.entryList).then((das) => {
        if (das.code === 200) {
          this.$notify({
            title: '成功',
            message: '这是一条成功的提示消息',
            type: 'success'
          })
          this.init();
        } else {
          this.$notify({
            title: '错误！',
            message: '请检查网络后重试！',
            type: 'error'
          })
        }
      })
    },
    // 限制选中
    selectableStatus: function (row, index) {
      if (row.isHire === 2) {
        return true;
      }
    },
    // 移除简历
    remOffice(val) {
      console.log("remOffice ", val);
      DelinterviewRecordAndResume(val.rcId, val.iaId).then((das) => {
        if (das.code === 200) {
          this.$notify({
            title: '成功',
            message: '这是一条成功的提示消息',
            type: 'success'
          })
        } else {
          this.$notify({
            title: '失败',
            message: '这是一条错失败的提示消息',
            type: 'error'
          })
        }
      })
    },
    // 发送office
    EditOffice(val) {
      if (val.firstInterview === undefined) {
        this.$notify({
          title: '未面试',
          message: '面试人员通过面试后，使用！',
          type: 'error'
        })
        return
      }
      if (val.isHire === 0) {
        this.dialogTableVisible = true;
        this.takeOn.rid = val.rid;
        this.takeOn.jobNumber = val.jdid;
        this.takeOn.mailIds = val.email;
        this.takeOn.applyToPosition = val.candidatePosition;
        this.takeOn.hired = val.candidate;
        this.takeOn.rcId = val.rcId;
        console.log(val)
      }
    },
    SendOffice() {
      sendEmailByIHandleSendOffice(this.takeOn).then((das) => {
        if (das.code === 200) {
          this.$notify({
            title: '成功',
            message: '这是一条成功的提示消息',
            type: 'success'
          })
        } else {
          this.$notify({
            title: '失败',
            message: '请检查网络后发送！',
            type: 'error'
          })
        }
        this.dialogTableVisible = false;
        this.init();
      })
    },
    switchPageNum(index) {
      this.paging.pageNum = index;
      this.loadInterviewPageInfo();
    },
    loadInterviewPageInfo() {
      getInterviewHandlePageInfo({
        pageNum: this.paging.pageNum,
        pageSize: this.paging.pageSize
      }).then(data => {
        console.log('面试处理数据', data)
        this.tabData = data.list;
      })
    },
    init() {
      this.loadInterviewPageInfo();
    }
  },
  created() {
    this.init();
  }
}
</script>
<style lang="scss" scoped>
@import "../../../assets/css/personnelCss/RecruitHeadcount";
</style>